package com.emuporium.gymrat.server.program;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.emuporium.gymrat.server.data.Program;
import com.emuporium.gymrat.server.data.ProgramDB;
import com.emuporium.gymrat.server.data.RoutineDB;
import com.emuporium.gymrat.server.data.Routine;

@SuppressWarnings("serial")
public class ProgramModifyServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		int programId = new Integer(request.getParameter("id")).intValue();
		Program program = ProgramDB.getProgram(programId);
		ArrayList<Routine> routines = RoutineDB.getRoutines(request.getRemoteUser());
		
		request.setAttribute("program", program);
		request.setAttribute("routines", routines);

		String url = "/program/modify.jsp";
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher(url);
		dispatcher.forward(request, response);
	}
}
